﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Uc_master_department_fv.ascx.vb"
    Inherits="Apps_Shares_Uc_master_department_fv" %>
<asp:FormView ID="fv" runat="server" RenderOuterTable="False" DataSourceID="fvSrc"
    DefaultMode="Insert" EnableModelValidation="True" Width="100%">
    <InsertItemTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#cccccc" border="1" align="center"
            width="60%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อระดับหน่วยงาน <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtDepartment' runat='server' CssClass='text_normal' Text='<%# Bind("master_department_name") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ระดับ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID='ddlLevel' runat='server' CssClass='text_normal' SelectedValue='<%# Bind("master_department_level") %>'>
                            <asp:ListItem Text='ระดับ' Value='0'></asp:ListItem>
                            <asp:ListItem Text='1' Value='1'></asp:ListItem>
                            <asp:ListItem Text='2' Value='2'></asp:ListItem>
                            <asp:ListItem Text='3' Value='3'></asp:ListItem>
                            <asp:ListItem Text='4' Value='4'></asp:ListItem>
                            <asp:ListItem Text='5' Value='5'></asp:ListItem>
                            <asp:ListItem Text='6' Value='6'></asp:ListItem>
                            <asp:ListItem Text='7' Value='7'></asp:ListItem>
                            <asp:ListItem Text='8' Value='8'></asp:ListItem>
                            <asp:ListItem Text='9' Value='9'></asp:ListItem>
                            <asp:ListItem Text='10' Value='10'></asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:RadioButtonList ID='rblStatus' runat='server' RepeatDirection="Horizontal" RepeatLayout='Flow'
                            SelectedValue='<%# Bind("master_department_status") %>'>
                            <asp:ListItem Text='ใช้งาน' Value='1' Selected="True"></asp:ListItem>
                            <asp:ListItem Text='ไม่ใช้งาน' Value='2'></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnSubmit' runat='server' Text='บันทึก' CommandName="Insert" ValidationGroup="g1" />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                        <div class="hide">
                            <asp:RequiredFieldValidator ID="txtDepartment_RequiredFieldValidator" runat="server"
                                ControlToValidate="txtDepartment" ErrorMessage="กรุณากรอกชือระดับหน่วยงาน" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="ddlLevel_RequiredFieldValidator" runat="server" ControlToValidate="ddlLevel"
                                ErrorMessage="กรุณาเลือกระดับหน่วยงาน" InitialValue="0" SetFocusOnError="True"
                                ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:ValidationSummary ID="fvValidationSummary" runat="server" ShowMessageBox="True"
                                ValidationGroup='g1' />
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </InsertItemTemplate>
    <EditItemTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#cccccc" border="1" align="center"
            width="60%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อระดับหน่วยงาน <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtDepartment' runat='server' CssClass='text_normal' Text='<%# Bind("master_department_name") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ระดับ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <%#Eval("master_department_level")%>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:RadioButtonList ID='rblStatus' runat='server' RepeatDirection="Horizontal" RepeatLayout='Flow'
                            SelectedValue='<%# Bind("master_department_status") %>'>
                            <asp:ListItem Text='ใช้งาน' Value='1'></asp:ListItem>
                            <asp:ListItem Text='ไม่ใช้งาน' Value='2'></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่สร้างข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ltrCreate' runat='server' Text='<%# Eval("Creator") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่ปรับปรุงข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ltrUpdate' runat='server' Text='<%# Eval("Editor") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnSubmit' runat='server' Text='บันทึก' CommandName="Update" ValidationGroup='g2' />
                        <asp:Button ID='btnCancel' runat='server' Text='ยกเลิก' PostBackUrl="~/Apps/master_department_list.aspx?Edit=true" />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                        <div class="hide">
                            <asp:RequiredFieldValidator ID="txtDepartment_RequiredFieldValidator" runat="server"
                                ControlToValidate="txtDepartment" ErrorMessage="กรุณากรอกชือระดับหน่วยงาน" ValidationGroup="g2"></asp:RequiredFieldValidator>
                            <br />
                            <br />
                            <asp:ValidationSummary ID="fvValidationSummary" runat="server" ShowMessageBox="True"
                                ValidationGroup='g2' />
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </EditItemTemplate>
    <ItemTemplate>
        <table bordercolor="#cccccc" border="1" align="center" width="60%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td width='50%' align="right" class="td_box">
                        ชื่อระดับหน่วยงาน :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='txtDepartment' runat='server' Text='<%# Eval("master_department_name") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ระดับ :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ddlLevel' runat='server' Text='<%# Eval("master_department_level") %>'>

                        </asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='Literal1' runat='server' Text='<%# CodeMatrix.Business.GenericData.GetStatusLabel(Eval("master_department_status")) %>'>
                        </asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่สร้างข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ltrCreate' runat='server' Text='<%# Eval("Creator") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่ปรับปรุงข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ltrUpdate' runat='server' Text='<%# Eval("Editor") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnBack' runat='server' Text='ย้อนกลับ' PostBackUrl="~/Apps/master_department_list.aspx" />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                    </td>
                </tr>
            </tbody>
        </table>
    </ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="fvSrc" runat="server" 
    ConnectionString="<%$ ConnectionStrings:GHBankConnectionString %>" 
    InsertCommand="INSERT INTO [master_department] ([master_department_name], [master_department_level], [master_department_status], [staff_code_create], [create_datetime], [staff_code_update], [update_datetime]) VALUES (@master_department_name, @master_department_level, @master_department_status, @staff_code_create, GETDATE(), @staff_code_update, GETDATE())" 
    SelectCommand="SELECT [master_department_code], [master_department_name], [master_department_level], [master_department_status], Creator = dbo.UFN_GetAuditor(staff_code_create,create_datetime) , Editor = dbo.UFN_GetAuditor(staff_code_update,update_datetime) FROM [master_department] WHERE ([master_department_code] = @master_department_code)" 
    UpdateCommand="UPDATE [master_department] SET [master_department_name] = @master_department_name, [master_department_status] = @master_department_status, [staff_code_update] = @staff_code_update, [update_datetime] = GETDATE() WHERE [master_department_code] = @master_department_code">
    <SelectParameters>
        <asp:QueryStringParameter Name="master_department_code" QueryStringField="Edit" Type="Int32" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="master_department_name" Type="String" />
        <asp:Parameter Name="master_department_status" Type="Int32" />
        <asp:QueryStringParameter Name="master_department_code" QueryStringField="Edit" Type="Int32" />
        <asp:SessionParameter Name="staff_code_update" Type="Int32" SessionField="staff_code" />
    </UpdateParameters>
    <InsertParameters>
        <asp:Parameter Name="master_department_name" Type="String" />
        <asp:Parameter Name="master_department_level" Type="Int32" />
        <asp:Parameter Name="master_department_status" Type="Int32" />
        <asp:SessionParameter Name="staff_code_create" Type="Int32" SessionField="staff_code" />
        <asp:SessionParameter Name="staff_code_update" Type="Int32" SessionField="staff_code" />
    </InsertParameters>
</asp:SqlDataSource>
